package com.tykboot.entity;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.tykboot.core.base.BaseEntity;
import com.tykboot.model.CurrencyAmount;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;

/**
 * CreditLine
 *
 * @author LiuYu
 */ 
@Entity
@Table(name = "tb_credit_line")
@GenericGenerator(name = "jpa-uuid", strategy = "uuid")
public class TbCreditLine extends BaseEntity {

	/**
	 * 
	 */
	@JsonIgnore
	@Id
	@GeneratedValue(generator = "jpa-uuid")
	@Column(name = "creditLineId")
	private String creditLineId;

	/**
	 * 
	 */
    @JsonIgnore
	@Column(name = "financialId")
	private String financialId;

	/**
	 * 
	 */
    @JsonIgnore
	@Column(name = "accountId")
	private String accountId;

	/**
	 * 
	 */ 
	@Column(name = "included")
	private Integer included;

	/**
	 * 
	 */
    @JsonIgnore
	@Column(name = "amount")
	private String amountDb;

	/**
	 * [ Pre-Agreed, Emergency, Temporary ]
	 */ 
	@Column(name = "type")
	private String type;

	@Transient
    private CurrencyAmount amount;

    public String getCreditLineId() {
        return creditLineId;
    }

    public void setCreditLineId(String creditLineId) {
        this.creditLineId = creditLineId;
    }

    public String getFinancialId() {
        return financialId;
    }

    public void setFinancialId(String financialId) {
        this.financialId = financialId;
    }

    public String getAccountId() {
        return accountId;
    }

    public void setAccountId(String accountId) {
        this.accountId = accountId;
    }

    public Integer getIncluded() {
        return included;
    }

    public void setIncluded(Integer included) {
        this.included = included;
    }

    public String getAmountDb() {
        return amountDb;
    }

    public void setAmountDb(String amountDb) {
        this.amountDb = amountDb;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public CurrencyAmount getAmount() {
        if (amount != null) {
            return amount;
        }
        return JSON.parseObject(JSON.toJSONString(JSON.parse(this.getAmountDb())), CurrencyAmount.class);
    }

    public void setAmount(CurrencyAmount amount) {
        this.amount = amount;
    }
}

